﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Telecom.Service;
using Telecom.Service.EntityCustom;
using TelecomGis.Helper.Control;

namespace TelecomGis.Controllers
{
    public class BanDoController : ContronllerBase
    {
        private readonly loaiBanDoSer _loaiBanDoSer = new loaiBanDoSer();
        private readonly vnptSiteSer _vnptSiteSer = new vnptSiteSer();
        private readonly loaiSiteSer _loaiSiteSer = new loaiSiteSer();
        private readonly quanhuyenPhuongXaSer _quanhuyenPhuongXaSer = new quanhuyenPhuongXaSer();
        private readonly LoaiCapService _LoaiCapService = new LoaiCapService();
        //
        // GET: /BanDo/

        public ActionResult Index()
        {
            return PartialView();
        }

        public string QuanHuyenList()
        {
            var _listEntity = _quanhuyenPhuongXaSer.getList_QH(UtContextgis._UserPageContext.QuanHuyenByUser);

            return JsonConvert.SerializeObject(_listEntity, Formatting.Indented,
                              new JsonSerializerSettings
                              {
                                  ReferenceLoopHandling = ReferenceLoopHandling.Ignore
                              });
        }

        public string ViewSiteOnMaps(string lopbando)
        {
            if (string.IsNullOrEmpty(lopbando))
            {
                var _listEntity = _vnptSiteSer.ViewVnptSiteOnmaps(null);

                return JsonConvert.SerializeObject(_listEntity, Formatting.Indented,
                                  new JsonSerializerSettings
                                  {
                                      ReferenceLoopHandling = ReferenceLoopHandling.Ignore
                                  });

                

            }
            else
            {

                var _listEntity = new List<VnptSiteLoadMaps>();

                if (lopbando == "0")
                {
                    var _arrayLoaiSite  = _loaiBanDoSer.getList().Select(p => p.LOP_ID).ToArray();
                    _listEntity = _vnptSiteSer.ViewVnptSiteOnmaps(_arrayLoaiSite);
                }
                else
                {

                    decimal[] _arrayLoaiSiteItem = Array.ConvertAll(lopbando.Split(','), s => decimal.Parse(s));
                    _listEntity = _vnptSiteSer.ViewVnptSiteOnmaps(_arrayLoaiSiteItem);
                }

                return JsonConvert.SerializeObject(_listEntity, Formatting.Indented,
                                  new JsonSerializerSettings
                                  {
                                      ReferenceLoopHandling = ReferenceLoopHandling.Ignore
                                  });
               

            }
        }

        public string listLopBanDo()
        {
            var _listEntity = _loaiBanDoSer.getListTree();

            return JsonConvert.SerializeObject(_listEntity, Formatting.Indented,
                              new JsonSerializerSettings
                              {
                                  ReferenceLoopHandling = ReferenceLoopHandling.Ignore
                              });
        }

        public string listLoaicapBanDo()
        {
            var _listEntity = _LoaiCapService.getListTree();

            return JsonConvert.SerializeObject(_listEntity, Formatting.Indented,
                              new JsonSerializerSettings
                              {
                                  ReferenceLoopHandling = ReferenceLoopHandling.Ignore
                              });
        }

    }
}
